package com.woniu.service.impl;

import com.woniu.entity.User;
import com.woniu.mapper.UserMapper;
import com.woniu.service.UserService;
import com.woniu.uitls.ResponseUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    @Override
    public List<User> findAll() {

        return userMapper.findAll();
    }

    @Override
    public Integer add(User user) {
        return userMapper.add(user);
    }

    @Override
    public ResponseUtil login(User user) {
        if (user.getName() == null || user.getPassword() == null) {
           return ResponseUtil.get(500, "用户名和密码不能为空");
        }
        User loginUser = userMapper.findByName(user.getName());
        if (loginUser == null) {
           return ResponseUtil.get(500, "用户名不正确");
        } else if (!loginUser.getPassword().equals(user.getPassword())) {
           return ResponseUtil.get(500, "密码不正确");
        } else {
            return ResponseUtil.get(200, "登陆成功",loginUser);
        }
    }

    @Override
    public Integer delete(Integer id) {
        return userMapper.delete(id);
    }
}
